<template>
  <div :class="['task-item', { 'urgent-task': task.urgent }]">
    <p :class="['task-text', { 'completed': task.completed }]" :style="{ color: task.priority === 'High' ? 'red' : 'black' }">
    <!--   具名插槽   -->
      {{ task.text }} - <span class="task-meta"> <slot name="priority">{{ task.priority }}</slot> | <slot name="type">{{ task.type }}</slot> </span>
      <span v-show="task.urgent" class="urgent-label">Urgent</span>
    </p>
    <!--  作用域插槽  -->
    <p>
      <slot :tips="tips"></slot>
    </p>
    <button @click="$emit('remove')" class="remove-btn">Remove</button>
  </div>
</template>

<script>
import { ref } from 'vue';
export default {
  name: 'TaskItem',
  props: {
    task: {
      type: Object,
      required: true
    }
  },
  setup() {
    let tips = ref("提示文字");
    return{
      tips
    }
  }
};
</script>

<style scoped>
.task-item {
  min-width: 600px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em;
  margin-bottom: 0.5em;
  background-color: white;
  border: 1px solid #eee;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s;
}

.task-item:hover {
  background-color: #f9f9f9;
}

.task-text {
  flex-grow: 1;
  margin: 0;
}

.task-meta {
  font-size: 0.85em;
  color: #666;
}

.completed {
  text-decoration: line-through;
}

.urgent-label {
  background-color: red;
  color: white;
  padding: 0.2em 0.5em;
  border-radius: 3px;
  font-size: 0.75em;
  margin-left: 1em;
}


.urgent-task {
  border-color: #2770a4;
}

.remove-btn {
  padding: 0.5em 1em;
  background-color: #dc3545;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s;
}

.remove-btn:hover {
  background-color: #c82333;
}
</style>
